// Change directory - Alter this command to the local copy of the "PrimaryModel" directory
cd "/Users/connorforsythe/Library/CloudStorage/Box-Box/CMU/Marginal Mileage Project/Publication Replication Code/NBER/PrimaryModel"
//Prevent graphics from popping up while running code
set graphics off

//determine log location depending on OS
if("`c(os)'"=="Windows"){
// 	log using "Logs\PrimaryModel.smcl", replace
	local tableSaveDir = "Tables\"
	local plotSaveDir = "Plots\"
	local pythonSaveDir = "PythonScripts\"
	local dataSaveDir = "Data/"
}
else{
// 	log using "Logs/PrimaryModel.smcl", replace
	local tableSaveDir = "Tables/"
	local plotSaveDir = "Plots/"
	local pythonSaveDir = "PythonScripts/"
	local dataSaveDir = "Data/"
}


clear
use "Data/baconData.dta", replace

gen impliedBetaVMT = bacVMTB/bacRegB 
gen impliedBetaGas = bacGasB/bacRegB 

//Save data
save "`dataSaveDir'baconData2", replace
export delimited "`dataSaveDir'baconData2.csv", replace

//Create plots for Goodman-Bacon Analysis
python script "`pythonSaveDir'PlotBacon2.py"


gen bacTreatYear = bacGasT 
gen bacControlYear = bacGasC

replace bacTreatYear = "" if bacGascgroup!=1
replace bacControlYear = "" if bacGascgroup!=1

destring bacTreatYear bacControlYear, replace

gen bacTreatControlYearDiff = abs(bacTreatYear-bacControlYear)

local sumVars = "bacRegB bacVMTB bacGasB impliedBetaVMT impliedBetaGas"
local sumVars = "bacRegB bacVMTB bacGasB"

sort bacVMTcgroup
by bacVMTcgroup: sum `sumVars' [aw = bacGasS],
by bacVMTcgroup: sum `sumVars' [aw = bacGasS] if bacTreatControlYearDiff>2, 

sum `sumVars' [aw = bacGasS],
sum `sumVars' [aw = bacGasS] if bacTreatControlYearDiff>2, 
